package com.lanyan.system.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.lanyan.system.domain.Sku;
import com.lanyan.system.service.ISkuService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 规格Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/sku")
public class SkuController extends BaseController
{
    @Autowired
    private ISkuService skuService;

    /**
     * 查询规格列表
     */
    @PreAuthorize("@ss.hasPermi('system:sku:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "skvValueId", value = "所属规格值", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "image", value = "规格图片", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "fullName", value = "全称", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "marketPrice", value = "划线价格", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "price", value = "一口价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "cost", value = "真实成本", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "stock", value = "库存", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "volume", value = "体积", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "weight", value = "重量", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "marketPrice", value = "成本价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "mate", value = "匹配", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
          @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    public TableDataInfo list(Sku sku)
    {
        startPage();
        List<Sku> list = skuService.selectSkuList(sku);
        return getDataTable(list);
    }

    /**
     * 导出规格列表
     */
    @PreAuthorize("@ss.hasPermi('system:sku:export')")
    @Log(title = "规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sku sku)
    {
        List<Sku> list = skuService.selectSkuList(sku);
        ExcelUtil<Sku> util = new ExcelUtil<Sku>(Sku.class);
        util.exportExcel(response, list, "规格数据");
    }

    /**
     * 获取规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sku:query')")
    @GetMapping(value = "/{skuId}")
    public AjaxResult getInfo(@PathVariable("skuId") Long skuId)
    {
        return success(skuService.selectSkuBySkuId(skuId));
    }

    /**
     * 新增规格
     */
    @PreAuthorize("@ss.hasPermi('system:sku:add')")
    @Log(title = "规格", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skvValueId", value = "所属规格值", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "image", value = "规格图片", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "fullName", value = "全称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "marketPrice", value = "划线价格", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "price", value = "一口价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "cost", value = "真实成本", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "stock", value = "库存", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "volume", value = "体积", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "weight", value = "重量", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "marketPrice", value = "成本价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "mate", value = "匹配", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody Sku sku)
    {
        return toAjax(skuService.insertSku(sku));
    }

    /**
     * 修改规格
     */
    @PreAuthorize("@ss.hasPermi('system:sku:edit')")
    @Log(title = "规格", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skvValueId", value = "所属规格值", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "image", value = "规格图片", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "fullName", value = "全称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "marketPrice", value = "划线价格", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "price", value = "一口价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "cost", value = "真实成本", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "stock", value = "库存", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "volume", value = "体积", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "weight", value = "重量", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "marketPrice", value = "成本价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "mate", value = "匹配", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody Sku sku)
    {
        return toAjax(skuService.updateSku(sku));
    }

    /**
     * 删除规格
     */
    @PreAuthorize("@ss.hasPermi('system:sku:remove')")
    @Log(title = "规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{skuIds}")
    public AjaxResult remove(@PathVariable Long[] skuIds)
    {
        return toAjax(skuService.deleteSkuBySkuIds(skuIds));
    }
}
